<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0">
<title>{echo admin_title()}</title>
<!--header-->
{template _:header}
</head>
<body>
<div class="layui-layout layui-layout-admin">
<!--top-->
{template _main_top}
<!--nav-->
{template _main_nav}
	<div class="position"><h1>员工列表</h1></div>
	<div class="layui-body admin-body">
		<div class="admin-content">
			<div class="searcher">
				<div class="right"><button type="button" class="layui-btn layui-add">添加员工</button></div>
				<form name="sch_form" id="sch_form" method="get" action="{echo \befen\get_url()}">
					<div class="layui-input-inline"><input type="text" name="wd" id="wd" class="layui-input" value="{echo input('param.wd')}" placeholder=""></div>
					<div class="layui-input-inline layui-left-margin"><button type="submit" id="search" class="layui-btn">查询</button></div>
				</form>
				<div class="clear"></div>
			</div>
			<form name="theform" id="theform" method="post" action="{echo \befen\get_url()}">
			<table class="layui-table">
				<thead>
					<tr>
						<th width="15%">账号</th>
						<th width="15%">姓名</th>
						<th width="20%">邮箱</th>
						<th width="20%">电话</th>
						<th width="10%">状态</th>
						<th width="20%">管理操作</th>
					</tr>
				</thead>
				<tbody>
					<!--{loop $list $key $val}-->
					<tr id="">
						<td>{$val[username]}</td>
						<td>{$val[pname]}</td>
						<td>{$val[email]}</td>
						<td>{$val[phone]}</td>
						<td>
							<input type="checkbox" class="check-slider" id="{$val[id]}" <!--{if $val['status'] == 1}-->checked<!--{/if}-->>
							<label class="input-slider" for="checkbox_{$val[id]}" onclick=""></label>
						</td>
						<td class="op">
							<a op="mod" val="{$val[username]}" lay-url="{echo url('admin/mod', ['id' => $val['id']])}" class="layui-btn layui-btn-xs layui-btn-normal">修改</a>
							<a op="del" val="{$val[username]}" lay-url="{echo url('admin/del', ['id' => $val['id']])}" class="layui-btn layui-btn-xs layui-btn-danger">删除</a>
						</td>
					</tr>
					<!--{/loop}-->
				</tbody>
			</table>
			</form>
			<div class="listpages">{$pagenav}</div>
		</div>
	</div>
</div>
<!--footer-->
{template _:footer}
<script type="text/javascript">
$(".layui-add").click(function(){
	showWindow('添加员工', '{echo url('admin/add')}', '500px');
});
$("a[op=mod]").click(function(){
	showWindow('修改员工', $(this).attr('lay-url'), '500px');
});
$("a[op=del]").click(function(){
	op('确认要删除 <font color="red">' + $(this).attr('val') + '</font> 吗？', $(this).attr('lay-url'));
});
$(".input-slider").click(function(){
	var obj = $(this).prev("input[type='checkbox']");
	var id = obj.attr("id");
	var cur_val = obj.prop("checked");
	$.ajax({
		type: "POST",
		dataType: "json",
		timeout: 50000,
		url: "{echo url('admin/status')}",
		data: {
			ajax: "json",
			id: id,
		},
		success: function(data){
			if(data.status == "nologin") {
				showAlert(data.message, function(){
					reload();
				});
			} else if(data.status == 0) {
				showAlert(data.message, function(){
					return;
				});
			} else if(data.status == 1) {
				obj.prop("checked", !cur_val);
				showInfo(data.message, function(){
					return;
				});
			}
		},
		error: function(data){
			showAlert("提交数据失败");
		},
		complete: function(){
			hideLoader();
		},
		beforeSend: function(){
			showLoader();
		}
	});
});
</script>
</body>
</html>